/**
 * 		Settings.java
 *  Adrián E. Córdoba 		16/06/2013
 */
package ar.com.adriancordoba.app.common.settings;

import java.util.Properties;

/**
 * @author Adrián E. Córdoba
 */
public abstract class Settings {
	private Properties properties = null;
	private String filename = null;

	protected abstract void loadSettings();

	protected abstract void saveSettings();

	public String getSetting(String key) {
		String value = properties.getProperty(key);
		if ((value != null) && (value.equals("")))
			value = null;
		return value;
	}

	public String getString(String key) {
		return getSetting(key);
	}

	public Character getCharacter(String key) {
		String value = getSetting(key);
		Character charValue = null;
		if (value != null && !value.equals(""))
			charValue = Character.valueOf(value.charAt(0));
		return charValue;
	}

	public Integer getInteger(String key) {
		String value = getSetting(key);
		Integer intValue = null;
		if (value != null && !value.equals(""))
			intValue = Integer.parseInt(value);
		return intValue;
	}

	public Long getLong(String key) {
		String value = getSetting(key);
		Long longValue = null;
		if (value != null && !value.equals(""))
			longValue = Long.parseLong(value);
		return longValue;
	}

	public Boolean getBoolean(String key) {
		String value = getSetting(key);
		Boolean booleanValue = null;
		if (value != null && !value.equals("")) {
			if (value.equals("y") || value.equals("yes") || value.equals("si")
					|| value.equals("true"))
				booleanValue = true;
			else if (value.equals("n") || value.equals("no")
					|| value.equals("false"))
				booleanValue = false;
		}
		return booleanValue;
	}

	public void setSetting(String key, String value) {
		properties.setProperty(key, value);
	}

	/**
	 * @return the properties
	 */
	public Properties getProperties() {
		return properties;
	}

	/**
	 * @param properties the properties to set
	 */
	public void setProperties(Properties properties) {
		this.properties = properties;
	}

	/**
	 * @return the filename
	 */
	public String getFilename() {
		return filename;
	}

	/**
	 * @param filename the filename to set
	 */
	public void setFilename(String filename) {
		this.filename = filename;
	}
}
